package wortubung.lang;

import static wortubung.util.CommonUtils.concat;
import wortubung.core.LANG;
import wortubung.inflection.CONJUGATION;
import wortubung.inflection.PERSON;

public class ReverseConjugationElement {
	private String verb;
	private CONJUGATION type;
	private PERSON[] persons;
	private boolean participePresent;
	private boolean participePasseM;

	ReverseConjugationElement(String verb, CONJUGATION type, PERSON person) {
		super();
		this.verb = verb;
		this.type = type;
		this.persons = new PERSON[]{ person };
	}

	public String getVerb() { return verb; }

	public boolean isParticipePresent() { return type == null && participePresent; }
	public boolean isParticipePasse() { return type == null && !participePresent; }
	public boolean isParticipePasseMasculin() { return participePasseM; }

	public CONJUGATION getType() { return type; }

	public PERSON[] getPersons() { return persons; }
	public String[] getPersonsDisplay(boolean longForm) {
		String[] ret = new String[persons.length];
		for (int i=persons.length-1; i>=0; --i)
			ret[i] = longForm ? persons[i].getName(LANG.fr) : persons[i].getShortName(LANG.fr);
		return ret;
	}
	public void addPerson(PERSON person) {
		PERSON[] newPsns = new PERSON[persons.length+1];
		for (int i=0; i<persons.length; ++i)
			newPsns[i] = persons[i];
		newPsns[persons.length]= person;
		persons = newPsns;
	}

	public static ReverseConjugationElement participePresent(String verb) {
		ReverseConjugationElement ret = new ReverseConjugationElement(verb, null, null);
		ret.participePresent = true;
		return ret;
	}

	public static ReverseConjugationElement participePasse(String verb, boolean isMasculin) {
		ReverseConjugationElement ret = new ReverseConjugationElement(verb, null, null);
		ret.participePresent = false;
		ret.participePasseM = isMasculin;
		return ret;
	}

	public String getDescription() {
		if (isParticipePresent())
			return "Participe Pr�sent";
		if (isParticipePasse())
			return isParticipePasseMasculin() ? "Participe Passé" : "Participe Passé (F)";
		return type.getDisplay(LANG.fr) + " (" + concat(',', getPersonsDisplay(true)) + ")";
	}
}
